style: Convert draw_spinner vfunc to Cairo version
authorBenjamin Otte <otte@redhat.com>
Mon, 16 Aug 2010 13:09:50 +0000 (15:09 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:02:59 +0000 (15:02 +0200)
gtk/gtkstyle.c
gtk/gtkstyle.h

index 87fb398987bb1358ed8837f2726c7e889a97791d..f9b92ad612c6c229e0e4dfa8d6c6e6af75321d70 100644 (file)
@@ -294,9 +294,8 @@ static void gtk_default_draw_resize_grip (GtkStyle       *style,
                                           gint            width,
                                           gint            height);
 static void gtk_default_draw_spinner     (GtkStyle       *style,
-                                         GdkWindow      *window,
+                                          cairo_t        *cr,
                                          GtkStateType    state_type,
-                                          GdkRectangle   *area,
                                           GtkWidget      *widget,
                                           const gchar    *detail,
                                          guint           step,
@@ -4269,9 +4268,8 @@ gtk_default_draw_resize_grip (GtkStyle       *style,
 
 static void
 gtk_default_draw_spinner (GtkStyle     *style,
-                          GdkWindow    *window,
+                          cairo_t      *cr,
                           GtkStateType  state_type,
-                          GdkRectangle *area,
                           GtkWidget    *widget,
                           const gchar  *detail,
                           guint         step,
@@ -4281,7 +4279,6 @@ gtk_default_draw_spinner (GtkStyle     *style,
                           gint          height)
 {
   GdkColor *color;
-  cairo_t *cr;
   guint num_steps;
   gdouble dx, dy;
   gdouble radius;
@@ -4294,9 +4291,6 @@ gtk_default_draw_spinner (GtkStyle     *style,
                  NULL);
   real_step = step % num_steps;
 
-  /* get cairo context */
-  cr = gdk_cairo_create (window);
-
   /* set a clip region for the expose event */
   cairo_rectangle (cr, x, y, width, height);
   cairo_clip (cr);
@@ -4339,9 +4333,6 @@ gtk_default_draw_spinner (GtkStyle     *style,
 
       cairo_restore (cr);
     }
-
-  /* free memory */
-  cairo_destroy (cr);
 }
 
 void
@@ -6299,13 +6290,59 @@ gtk_paint_spinner (GtkStyle           *style,
                   gint                width,
                   gint                height)
 {
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_spinner (style, window, state_type,
-                                             (GdkRectangle *)area, widget, detail,
+  cr = gtk_style_cairo_create (window, area);
+
+  gtk_cairo_paint_spinner (style, cr, state_type,
+                           widget, detail,
+                          step, x, y, width, height);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_spinner:
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @widget: (allow-none): the widget (may be %NULL)
+ * @detail: (allow-none): a style detail (may be %NULL)
+ * @step: the nth step, a value between 0 and #GtkSpinner:num-steps
+ * @x: the x origin of the rectangle in which to draw the spinner
+ * @y: the y origin of the rectangle in which to draw the spinner
+ * @width: the width of the rectangle in which to draw the spinner
+ * @height: the height of the rectangle in which to draw the spinner
+ *
+ * Draws a spinner on @window using the given parameters.
+ */
+void
+gtk_cairo_paint_spinner (GtkStyle           *style,
+                         cairo_t            *cr,
+                         GtkStateType        state_type,
+                         GtkWidget          *widget,
+                         const gchar        *detail,
+                         guint               step,
+                         gint                x,
+                         gint                y,
+                         gint                width,
+                         gint                height)
+{
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_spinner != NULL);
+
+  cairo_save (cr);
+
+  GTK_STYLE_GET_CLASS (style)->draw_spinner (style, cr, state_type,
+                                             widget, detail,
                                             step, x, y, width, height);
+
+  cairo_restore (cr);
 }
 
 /**
index c7c0fead29a7e4bc0f85c701e72e6617e8157c0b..a300829b758bfe91a11daa94a17e5fbf8d93057b 100644 (file)
@@ -360,9 +360,8 @@ struct _GtkStyleClass
                                 gint                    width,
                                 gint                    height);
   void (*draw_spinner)          (GtkStyle              *style,
-                                GdkWindow              *window,
+                                 cairo_t                *cr,
                                 GtkStateType            state_type,
-                                GdkRectangle           *area,
                                 GtkWidget              *widget,
                                 const gchar            *detail,
                                 guint                   step,
@@ -840,17 +839,28 @@ void gtk_cairo_paint_resize_grip (GtkStyle           *style,
                                   gint                y,
                                   gint                width,
                                   gint                height);
-void gtk_paint_spinner     (GtkStyle           *style,
-                           GdkWindow          *window,
-                           GtkStateType        state_type,
-                            const GdkRectangle *area,
-                            GtkWidget          *widget,
-                            const gchar        *detail,
-                           guint               step,
-                           gint                x,
-                           gint                y,
-                           gint                width,
-                           gint                height);
+void gtk_paint_spinner           (GtkStyle           *style,
+                                  GdkWindow          *window,
+                                  GtkStateType        state_type,
+                                  const GdkRectangle *area,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  guint               step,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
+void gtk_cairo_paint_spinner     (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  guint               step,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
+
 
 GType      gtk_border_get_type (void) G_GNUC_CONST;
 GtkBorder *gtk_border_new      (void) G_GNUC_MALLOC;